package com.reger.canal.server;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.Resource;

public class CanalServerConfiguration {
	@Bean(initMethod = "start", destroyMethod = "stop")
	public CanalController controller(ApplicationContext ctx) throws IOException {
		Resource canal = ctx.getResource("classpath:canal.properties");
		InputStream canalInputStream = canal.getInputStream();
		try {
			Properties properties = new Properties();
			properties.load(canalInputStream);
			return new CanalController(properties);
		} finally {
			canalInputStream.close();
		}
	}
}
